<template>
    <el-table :data="multidata" stripe style="width:600px" @selection-change="handleSelectionChange">
        <el-table-column type="selection" />
        <el-table-column prop="name" label="姓名" width="66" v-if="props.type == 1" />
        <el-table-column prop="Account" label="账号" width="66" v-if="props.type == 1" />
        <el-table-column prop="works" label="公开作品数" width="95" v-if="props.type == 1" />
        <el-table-column prop="editor" label="编辑作品数" width="95" v-if="props.type == 1" />
        <el-table-column prop="like" label="点赞数" width="66" v-if="props.type == 1" />
        <el-table-column prop="review" label="评论数" width="66" v-if="props.type == 1" />
        <el-table-column prop="grade" label="班级名称" v-if="props.type == 2" />
        <el-table-column prop="id" label="ID" v-if="props.type == 2" />
        <el-table-column prop="teacher" label="指导老师" v-if="props.type == 2" />
        <el-table-column prop="mingzi" label="姓名" v-if="props.type == 3" />
        <el-table-column prop="zhanghaos" label="账号" v-if="props.type == 3" />
        <el-table-column prop="namess" label="真实姓名" v-if="props.type == 3" />
        <el-table-column prop="phone" label="手机号" v-if="props.type == 3" />
        <el-table-column prop="teacher" width="145">
            <template #default="scope">
                <span>
                    <span size="small" v-if="props.type == 3">
                        班级设置
                    </span>
                </span>
                <span size="small" @click="handleEdit(scope.row)">
                    设置
                </span>
                <span size="small" type="danger" @click="handleDelete(scope.row.id)">
                    删除
                </span>
            </template>
        </el-table-column>
    </el-table>
</template>

<script setup>
import { ref, provide, reactive, inject, defineProps, defineEmits } from "vue"
import { delbanji, delguan, banjidata, deljiaoshi } from "../api/index.ts"
import { userPiniaStore } from "@/stores"
const pinia = userPiniaStore()
const id = ref("")
//接收父组件传过来的数据
const props = defineProps(["multidata", "type"])
const dianji = inject("dianji")
const emmit = defineEmits(["deldata"])
const del = async () => {
    const res = await banjidata()
    emmit("deldata", res.data.data)
}
const handleEdit = (row) => {
    dianji()
    id.value = row.id
    pinia.setbanji(row)
}

const handleDelete = async (row) => {
    if (props.type == 1) {
        const commit = window.confirm("确定删除吗？")
        if (commit) {
            const res = await delbanji(row)
            if (res.data.code == 0) {
                alert(res.data.msg)
            }
        }
        del()
    } else if (props.type == 2) {
        const commit = window.confirm("确定删除吗？")
        if (commit) {
            const res = await delguan(row)
            alert(res.data.msg)
            pinia.setdelgyanbanji(res.data.data)
        }

    } else if (props.type == 3) {
        const commit = window.confirm("确定删除吗？")
        if (commit) {
            const res = await deljiaoshi(row)
            alert(res.data.msg)
            pinia.setdelgyanTeacher(res.data.data)
        }
    }
}

const handleSelectionChange = (val) => {
    if (props.type == 1) {
        console.log(val)
        console.log(11111111)
        pinia.getbanjidata(val)

    } else if (props.type == 2) {
        console.log(val)
        console.log(222222222222)
        pinia.setbatchdelguan(val)

    } else if (props.type == 3) {
        console.log(val)
        console.log(33333333333)
        pinia.setbatchdelteacher(val)
    }
}



</script>

<style scoped>
span {
    cursor: pointer;
}
</style>